package com.personal.mapper;

import com.personal.pojo.Blogs;
import com.personal.pojo.BlogsCover;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogsMapper {

    @Insert("insert into blogs(user_id, title, image, content, create_time, update_time) values (#{user_id},#{title},#{image},#{content},#{createTime},#{updateTime})")
    int add(Blogs blogs);

    @Select("select id, user_id, title, image, content, create_time, update_time from blogs where user_id = #{id} order by id desc")
    List<Blogs> getBlogsByUserId(String id);

    @Delete("delete from blogs where id = #{id}")
    int delete(String id);

    int update(Blogs blogs);

    @Select("select id, user_id, title, image, content, create_time, update_time from blogs order by id desc")
    List<Blogs> getAllBlogs();

    @Select("select id, user_id, title, image, content, create_time, update_time from blogs order by id desc limit #{pageNum},#{pageSize}")
    List<Blogs> getBlogsByTitle(int pageNum, int pageSize);

    List<BlogsCover> getAllBlogsCover();

    List<BlogsCover> getMyBlogsCoverById(Integer id);

    @Select("select id, user_id, title, image, content, create_time, update_time from blogs where id = #{id}")
    Blogs getOneBlogsById(Integer id);

    @Select("select id, user_id, title, image, content, create_time, update_time from blogs where title like concat('%',#{title},'%')")
    List<Blogs> searchBlogsByTitle(String title);


    BlogsCover searchBlogsByBlogsId(int id);
}
